/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package engine.skill;

import engine.ani.Animation;
import engine.ani.Player;
import javax.microedition.lcdui.Graphics;
import mainpackage.Constant;
import mainpackage.MainView;
import mainpackage.ResManager;
import mainpackage.Tools;

/**
 *
 * @author Administrator
 */
public class SkillAni {
    //动画ID
//    private String strSkillActId;
    //准备光效id

    private String strStartId;
    //准备光效x,y位置
    private int iStartX, iStartY;
    //释放技能单位id
    private int iUseUnitId;
    //释放技能单位种类
    private byte byUseUnit;
    //释放单位索引(玩家除外)
    private short shUseUnitIndex;
    //结果光效id
    private String strEndId;
    //异常状态光效id
    private short shStateId;
    //结果光效xy位置
    private int iEndX, iEndY;
    //目标单位id
    private int iAimId;
    //目标对象种类(0npc,1其他玩家,2玩家)
    private byte byAimType;
    //目标对象所在数组索引(玩家自己不用)
    private short shAimIndex;
    //当前播放阶段(1准备2爆炸)
    private byte bySegment;
    //技能方向
    private byte byDirect;
    //技进入飞行和爆炸阶段前需要等待的动作总帧数
    private short shFrameNum;
    //技能使用时间
    private long lSkillUseTime;
    //技能播放时间
    private long lSkillActTime;
    //技能计算帧数操作延迟时间
    private int iTimeDelay;
    //技能准备阶段动画延迟时间
    private int iTimeDelayReady;
    //技能爆炸阶段动画延迟时间
    private int iTimeDelayBlast;
    //技能状态光效使用时间
    private long lSkillStateUseTime;
    //状态持续时间
    private int iSkillStateTime;
    //技能爆炸阶段动画帧数
    private short shEndFrameNum;
    //技能爆炸阶段动画帧计数延迟
    private int iSkillEndCountDelay;
    public Animation aniSkill;
    //相对屏幕坐标
    public int iSkillAniX = 0;
    public int iSkillAniY = 0;
    public int iActPreIndex = 0;
    //当前技能播放阶段
    public String strCurentSkillStep = null;
    public byte byCurrentSkillStep = 0;
    public int type = 0;
    private int[] iAniStatus = null;
//    private byte byDirect =0 ;

    public SkillAni(int type, int screenOffX, int screenOffY, int x, int y, int endx, int endy, int actPreIndex, String firstActid, String secondActid, byte direct) {
        try {
            Tools.printLog("添加一个技能光效：type:" + type + "x:" + x + "y:" + y + "endx:" + endx + "endy:" + endy + "firstActid:" + firstActid + "secondActid:" + secondActid + "direct:" + direct);
            if (direct == 0) {
                direct = 1;
            } else if (direct == 1) {
                direct = 0;
            }
            this.type = type;
            byDirect = direct;
            this.iStartX = x;
            this.iStartY = y;
            this.iEndX = endx;
            this.iEndY = endy;
            this.iSkillAniX = screenOffX;
            this.iSkillAniY = screenOffY;
            this.iActPreIndex = actPreIndex;
            this.strStartId = firstActid;
            this.strEndId = secondActid;
            iAniStatus = new int[5];
//            for (int i = 0; i < 5; i++)
//            {
//             this.iAniStatus[i] = 0;
//            }
            int actid = 0;
            if ((Integer.parseInt(firstActid) == 0 && Integer.parseInt(secondActid) == 0) || (Integer.parseInt(firstActid) == -1 && Integer.parseInt(secondActid) == -1) || (Integer.parseInt(firstActid) == 0 && Integer.parseInt(secondActid) == -1) || (Integer.parseInt(firstActid) == -1 && Integer.parseInt(secondActid) == 0)) {
                return;
            }
            if (Integer.parseInt(firstActid) == 0 || Integer.parseInt(firstActid) == -1) {
                strCurentSkillStep = secondActid;
                actid = Integer.parseInt(secondActid);
                byCurrentSkillStep = 1;
            } else {
                strCurentSkillStep = firstActid;
                actid = Integer.parseInt(firstActid);
                byCurrentSkillStep = 0;
            }
            for (int i = 0; i < 5; i++) {
                this.iAniStatus[i] = 0;
            }
            aniSkill = ResManager.loadAnimation(actid, Constant.RES_PUBLIC_ONEROOM, false);
            if (aniSkill != null) {
//                switch (byDirect) {
//                    case Constant.PLAYER_DIRECTION_UP:
//                        byDirect = Constant.PLAYER_DIRECTION_DOWN;
//                        break;
//                    case Constant.PLAYER_DIRECTION_DOWN:
//                        byDirect = Constant.PLAYER_DIRECTION_UP;
//                        break;
//                }
                aniSkill.changeAction(byDirect, 0, this.iAniStatus);
            }

        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    public void drawSkillAni(Graphics g, int x, int y) {
        try {

            if (this.aniSkill == null || SkillManager.strSkillActPrePosX == null) {
                return;
            }
            if (byCurrentSkillStep == 0) {
                this.aniSkill.show(g, this.iStartX - x, this.iStartY - y, this.iAniStatus, false, false);
            } else {
                this.aniSkill.show(g, this.iEndX - x, this.iEndY - y - SkillManager.getSecFlarePosY(iActPreIndex), this.iAniStatus, false, false);
//            System.err.println(" SkillManager.getSecFlarePosY(iActPreIndex)"+ SkillManager.getSecFlarePosY(iActPreIndex));
            }
            this.aniSkill.nextFrame(this.iAniStatus, false);
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

//    public void show(Graphics g, int x, int y)
//    {
//        super.show(g, iSkillAniX + iStartX, iSkillAniY + iStartY);
//        this.nextFrame(false);
//    }
    /**
     * 初始化当前技能光效为准备光效
     * @param ani Animation 动画播放器
     */
    public void initSkillStartAni(Animation ani, byte byDirect) {
        if (this.strStartId != null || !this.strStartId.equals("")) {
            switch (byDirect) {
                case 2: //left
                    break;
                case 3: //right
                    break;
                case 0: //up
                    break;
                case 1: //down
                    break;
            }
        }
    }

    public boolean blCanremove() {
        try {
            if (this.iAniStatus[4] == 1) {
                if (byCurrentSkillStep == 0) {
                    byCurrentSkillStep = 1;
                    if (Integer.parseInt(this.strEndId) == 0 || Integer.parseInt(this.strEndId) == -1) {
                        byCurrentSkillStep = -1;
                        return true;
                    } else {
                        for (int i = 0; i < 5; i++) {
                            this.iAniStatus[i] = 0;
                        }
                        aniSkill = ResManager.loadAnimation(strEndId, Constant.RES_PUBLIC_ONEROOM, false);
//                          if(aniSkill == null)
//                              return true;
                        if (aniSkill != null) {
//                            switch (byDirect) {
//                                case Constant.PLAYER_DIRECTION_UP:
//                                    byDirect = Constant.PLAYER_DIRECTION_DOWN;
//                                    break;
//                                case Constant.PLAYER_DIRECTION_DOWN:
//                                    byDirect = Constant.PLAYER_DIRECTION_UP;
//                                    break;
//                            }
                            aniSkill.changeAction(byDirect, 0, this.iAniStatus);
                        }
                    }
                } else if (byCurrentSkillStep == 1) {
                    byCurrentSkillStep = -1;
                    return true;
                }
            }
            if (this.type == Constant.SKILL_TYPE_PLAYER)//玩家使用技能
            {
                if (aniSkill == null) {
                    return true;
                }
                /*
                //如果到振屏的frame
                if (byCurrentSkillStep == 0 && aniSkill.getmFrameIndex() == SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 5] && SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 6] > 0) {
                    MainView.blStartScreenShake = true;
                } else if (byCurrentSkillStep == 1 && aniSkill.getmFrameIndex() == SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 7] && SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 8] > 0) {
                    MainView.blStartScreenShake = true;
                }
                //如果到振屏的frame
                if (byCurrentSkillStep == 0 && aniSkill.getmFrameIndex() == SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 9] && SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 10] > 0) {
                    SkillManager.iSkillFalshNums = SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 10];

                    MainView.blStartScreenFlash = true;
                } else if (byCurrentSkillStep == 1 && aniSkill.getmFrameIndex() == SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 11] && SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 12] > 0) {
                    SkillManager.iSkillFalshNums = SkillManager.bySkillActPreFirstActTim[iActPreIndex * SkillManager.iSkillActFlareNums + 12];
                    MainView.blStartScreenFlash = true;
                }
                */
            } else if (this.type == Constant.SKILL_TYPE_PLAYER_HEART)//玩家使用技能
            {
                if (aniSkill == null) {
                    return true;
                }
                int frameindex = aniSkill.getmFrameIndex();
                int indexAbout = iActPreIndex + ((Player.byPlayerSex == Constant.PLAYER_SEX_WOMAN) ? 4 : 3);
                Tools.printLog("indexAbout" + indexAbout + "iActPreIndex" + iActPreIndex);
                /*
                if (SkillManager.iSkillActJobAct[indexAbout] != -1) {
                    //如果到振屏的frame
                    for (int i = 0; i < 3; i++) {
                        if (frameindex == (SkillManager.bySkillActJobActTim[SkillManager.iSkillActJobAct[indexAbout] * SkillManager.iSkillActJobFlareNums + i * 2 + 1])) {
                            SkillManager.iSkillFalshNums = SkillManager.bySkillActJobActTim[SkillManager.iSkillActJobAct[indexAbout] * SkillManager.iSkillActJobFlareNums + i * 2 + 2];
                            MainView.blStartScreenFlash = true;
                        }
                        //如果到振屏的frame
                        if (frameindex == (SkillManager.bySkillActJobActTim[SkillManager.iSkillActJobAct[indexAbout] * SkillManager.iSkillActJobFlareNums + i * 2 + 1 + 8])) {
                            SkillManager.iSkillShakeNums = (SkillManager.bySkillActJobActTim[SkillManager.iSkillActJobAct[indexAbout] * SkillManager.iSkillActJobFlareNums + i * 2 + 1 + 9]);
                            MainView.blStartScreenShake = true;
                        }
                    }
                }*/
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
        return false;
    }

    public byte getByAimType() {
        return byAimType;
    }

    public byte getBySegment() {
        return bySegment;
    }

    public short getShAimIndex() {
        return shAimIndex;
    }

    public String getShEndId() {
        return strEndId;
    }

    public String getshStartKey() {
        return strStartId;
    }

    public int getIEndX() {
        return iEndX;
    }

    public int getIEndY() {
        return iEndY;
    }

    public int getIStartX() {
        return iStartX;
    }

    public int getIReadyY() {
        return iStartY;
    }

    public byte getByUseUnit() {
        return byUseUnit;
    }

    public short getShUseUnitIndex() {
        return shUseUnitIndex;
    }

    public byte getByDirect() {
        return byDirect;
    }

    public int getIAimId() {
        return iAimId;
    }

    public short getShFrameNum() {
        return shFrameNum;
    }

    public int getITimeDelay() {
        return iTimeDelay;
    }

    public int getITimeDelayBlast() {
        return iTimeDelayBlast;
    }

    public int getITimeDelayReady() {
        return iTimeDelayReady;
    }

    public long getLSkillUseTime() {
        return lSkillStateUseTime;
    }

    public long getLSkillStartUseTime() {
        return lSkillUseTime;
    }

    public int getISkillStateTime() {
        return iSkillStateTime;
    }

    public short getShStateId() {
        return shStateId;
    }

    public short getShEndFrameNum() {
        return shEndFrameNum;
    }

    public int getISkillEndCountDelay() {
        return iSkillEndCountDelay;
    }

    public int getIUseUnitId() {
        return iUseUnitId;
    }

    public long getLSkillActTime() {
        return lSkillActTime;
    }

    public void setByAimType(byte byAimType) {
        this.byAimType = byAimType;
    }

    public void setBySegment(byte bySegment) {
        this.bySegment = bySegment;
    }

    public void setShAimIndex(short shAimIndex) {
        this.shAimIndex = shAimIndex;
    }

    public void setStrEndKey(String shEndId) {
        this.strEndId = shEndId;
    }

    public void setStrStartKey(String strStartId) {
        this.strStartId = strStartId;
    }

    public void setIEndX(int iEndX) {
        this.iEndX = iEndX;
    }

    public void setIEndY(int iEndY) {
        this.iEndY = iEndY;
    }

    public void setByUseUnit(byte byUseUnit) {
        this.byUseUnit = byUseUnit;
    }

    public void setShUseUnitIndex(short shUseUnitIndex) {
        this.shUseUnitIndex = shUseUnitIndex;
    }

    public void setByDirect(byte byDirect) {
        this.byDirect = byDirect;
    }

    public void setIAimId(int iAimId) {
        this.iAimId = iAimId;
    }

    public void setShFrameNum(short shFrameNum) {
        this.shFrameNum = shFrameNum;
    }

    public void setITimeDelay(int iTimeDelay) {
        this.iTimeDelay = iTimeDelay;
    }

    public void setITimeDelayBlast(int iTimeDelayBlast) {
        this.iTimeDelayBlast = iTimeDelayBlast;
    }

    public void setITimeDelayReady(int iTimeDelayReady) {
        this.iTimeDelayReady = iTimeDelayReady;
    }

    public void setLSkillUseTime(long lSkillUseTime) {
        this.lSkillStateUseTime = lSkillUseTime;
    }

    public void setLSkillStartUseTime(long lSkillUseTime) {
        this.lSkillUseTime = lSkillUseTime;
    }

    public void setISkillStateTime(int iSkillStateTime) {
        this.iSkillStateTime = iSkillStateTime;
    }

    public void setShStateId(short shStateId) {
        this.shStateId = shStateId;
    }

    public void setShEndFrameNum(short shEndFrameNum) {
        this.shEndFrameNum = shEndFrameNum;
    }

    public void setISkillEndCountDelay(int iSkillEndCountDelay) {
        this.iSkillEndCountDelay = iSkillEndCountDelay;
    }

    public void setIUseUnitId(int iUseUnitId) {
        this.iUseUnitId = iUseUnitId;
    }

    public void setLSkillActTime(long lSkillActTime) {
        this.lSkillActTime = lSkillActTime;
    }

    public void setIStartX(int iStartX) {
        this.iStartX = iStartX;
    }

    public void setIStartY(int iStartY) {
        this.iStartY = iStartY;
    }
}
